﻿using ZFine.Code;
using System.Web.Mvc;
using System.Configuration;
using System.Threading.Tasks;

namespace ZFine.Web
{
    [HandlerLogin]
    public abstract class ControllerBase : Controller
    {

        #region 字典数据
        protected static string systemlist = ConfigurationManager.AppSettings["systemlistParameter"];//总后台超级管理员f_account
        protected static string newstype = ConfigurationManager.AppSettings["NewsParameter"];//新闻
        protected static string Linktype = ConfigurationManager.AppSettings["LinkParameter"];//相关链接
        protected static string LeaderType = ConfigurationManager.AppSettings["LeaderParameter"];//领导之窗
        protected static string CommitteesNameList = ConfigurationManager.AppSettings["CommitteesNameListParameter"];
        //直属单位、专门委员会、党建办
        protected static string Directly = ConfigurationManager.AppSettings["DirectlyParameter"];//直属单位
        protected static string Committee = ConfigurationManager.AppSettings["CommitteeParameter"];//专门委员会
        protected static string TheParty = ConfigurationManager.AppSettings["ThePartyParameter"];//党建办
        //规范性文件+专题专栏
        protected static string NormativeDocuments = ConfigurationManager.AppSettings["NormativeDocumentsParameter"];//规范性文件
        protected static string SpecialTopic = ConfigurationManager.AppSettings["SpecialTopicParameter"];//专题专栏
        //直属商会
        protected static string Industry = ConfigurationManager.AppSettings["IndustryParameter"];//行业商会
        protected static string Remote = ConfigurationManager.AppSettings["RemoteParameter"];//异地商会
        protected static string Other = ConfigurationManager.AppSettings["OtherParameter"];//内蒙古女企业家商会
        //法律法规
        protected static string Latest = ConfigurationManager.AppSettings["LatestParameter"];//最新政策
        protected static string Policy = ConfigurationManager.AppSettings["PolicyParameter"];//政策解读
        protected static string Laws = ConfigurationManager.AppSettings["LawsParameter"];//法律法规

        //企业数据
        protected static string CompanyType = ConfigurationManager.AppSettings["CompanyTypeParameter"];//公司类型
        protected static string BelongIndustry = ConfigurationManager.AppSettings["BelongIndustryParameter"];//所属行业

        protected static string Consulting = ConfigurationManager.AppSettings["ConsultingParameter"];//投诉咨询
        //供求信息、服务信息
        protected static string TradeLeads = ConfigurationManager.AppSettings["TradeLeadsParameter"];//供求信息
        protected static string ServiceType = ConfigurationManager.AppSettings["ServiceTypeParameter"];//服务信息

        protected static string websitcahcekey = ConfigurationManager.AppSettings["WebSiteCahceKey"];//网站缓冲
        protected static string WebLinkcachekey = ConfigurationManager.AppSettings["WebLinkcachekey"];//关于网站缓冲
        #endregion


        #region 属性
        protected static ICache cache = new Cache(); 
        #endregion
        public Log FileLog
        {
            get { return LogFactory.GetLogger(this.GetType().ToString()); }
        }
        [HttpGet]
        [HandlerAuthorize]
        public virtual ActionResult Index()
        {
            return View();
        }
        [HttpGet]
        [HandlerAuthorize]
        public virtual ActionResult Form()
        {
            return View();
        }
        [HttpGet]
        [HandlerAuthorize]
        public virtual ActionResult Details()
        {
            return View();
        }
        protected virtual ActionResult Success(string message)
        {
            return Content(new AjaxResult { state = ResultType.success.ToString(), message = message }.ToJson());
        }
        protected virtual ActionResult Success(string message, object data)
        {
            return Content(new AjaxResult { state = ResultType.success.ToString(), message = message, data = data }.ToJson());
        }
        protected virtual ActionResult Error(string message)
        {
            return Content(new AjaxResult { state = ResultType.error.ToString(), message = message }.ToJson());
        }
        protected virtual ActionResult Warn(string message)
        {
            return Content(new AjaxResult { state = ResultType.warning.ToString(), message = message }.ToJson());
        }

        public async void AsyncMethod(string cahcekey)
        {
            await RemoveCacheValues(cahcekey);
        }

        static async Task<int> RemoveCacheValues(string key)
        {
            cache.RemoveCache(key);
            return 0;
        }
    }
}
